import request from '@/utils/request'
import { CopyJson } from '@/utils/index'

/**
 * @description 获取列表所有数据
 */
export function getListAll(params) {
  const data = {
    userId: params.item.userId * 1
  }

  return request({
    url: `queryUserDeviceByUserid?params=${JSON.stringify(data)}`,
    method: 'post'
  })
}

/**
 * @description 获取列表
 */
export function getList(params) {
  const data = {
    userId: params.item.userId * 1,
    page: params.page.num,
    dataNum: params.page.size,
    company: params.item.company,
    deviceMac: params.item.deviceMac,
    addressP: (params.item.addressPArr.length !== 0) ? params.item.addressPArr.join('/') : '',
    state: (params.item.state !== '') ? params.item.state : 2,
    deviceModel: '',
    deviceType: '',
    startAddTime: (params.item.addTimeArr.length) ? params.item.addTimeArr[0] : '',
    endAddTime: (params.item.addTimeArr.length) ? params.item.addTimeArr[1] : ''
  }
  return request({
    url: `queryDevice?params=${JSON.stringify(data)}`,
    // url: `queryUserDeviceByUseridPage?params=${JSON.stringify(data)}`,
    method: 'post'
  })
}

/**
 * @description 获取详情
 */
export function getDetail(params) {
  const data = {
    deviceMac: params.deviceMac
  }
  return request({
    url: `queryDeviceByDeviceMac?params=${JSON.stringify(data)}`,
    method: 'post'
  })
}

/**
 * @description 添加保存
 * @param {*} params
 */
export function addSave(params) {
  const data = CopyJson(params)
  delete data.addressPArr
  return request({
    url: `updataDevice?params=${JSON.stringify(data)}`,
    method: 'post'
  })
}

/**
 * @description 编辑保存
 * @param {*} params
 */
export function updateSave(params) {
  const data = CopyJson(params)
  delete data.addressPArr
  return request({
    url: `updataDevice?params=${JSON.stringify(data)}`,
    method: 'post'
  })
}

/**
 * @description 删除保存
 * @param {*} params
 */
export function deleteSave(params) {
  const data = CopyJson(params)
  return request({
    url: `delUserInfo?params=${JSON.stringify(data)}`,
    method: 'post'
  })
}

/**
 * @description 根据服务商ID获取设备编号和名称
 */
export function getIspDevice(params) {
  const data = {
    userInfoId: params.userInfoId * 1,
    page: 1000,
    dataNum: 0
  }
  return request({
    url: `queryDeviceByUserInfoIdPage?params=${JSON.stringify(data)}`,
    method: 'post'
  })
}

/**
 * @description 导出接口
 */
export function exportExcel(params) {
  const data = {
    userId: params.item.userId * 1,
    company: params.item.company,
    deviceMac: params.item.deviceMac,
    addressP: (params.item.addressPArr.length !== 0) ? params.item.addressPArr.join('/') : '',
    state: (params.item.state !== '') ? params.item.state : 2,
    startAddTime: (params.item.addTimeArr.length) ? params.item.addTimeArr[0] : '',
    endAddTime: (params.item.addTimeArr.length) ? params.item.addTimeArr[1] : ''
  }
  return `${process.env.BASE_API}queryDeviceExcel?params=${JSON.stringify(data)}`
}

/**
 *
 * @description 查询登录账户下全部服务商名称信息
 * @param {*} userId  登陆用户ID
 */
export function unbindUserInfoDevice(userId, deviceMac) {
  const data = {
    userId: userId * 1,
    deviceMac: deviceMac
  }
  return request({
    url: `unbindUserInfoDevice?params=${JSON.stringify(data)}`,
    method: 'post'
  })
}

export default {
}
